package com.cyou.nad.utils;

import java.util.Date;

import org.apache.commons.lang.builder.StandardToStringStyle;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.time.DateFormatUtils;

/**
 * 在使用ToStringBuilder是使用此类比较方便
 * 比如
 * public String toString() {
		return ToStringBuilder.reflectionToString(this, MyToStringStyle.getInstance());
	}
 * @author  luzhaoman@sohu-rd.com Sep 29, 2010 3:03:27 PM
 *
 */
public class MyToStringStyle extends StandardToStringStyle {

	private static final long serialVersionUID = 5085557083685023322L;
	private static MyToStringStyle myToStringStyle = new MyToStringStyle();

	public static MyToStringStyle getInstance() {
		return myToStringStyle;
	}

	private MyToStringStyle() {
		super();
		setUseShortClassName(true);
	}

	protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
		if (value instanceof Date) {
			buffer.append(DateFormatUtils.format((Date) value, "yyyy-MM-dd HH:mm:ss"));
		} else {
			buffer.append(value);
		}

	}
}